#coding=utf-8
import uliweb.form as form

class TestForm(form.Form):
    def form_validate(self, data):
        from uliweb.orm import get_model
        from sqlalchemy.sql import and_, or_, not_
        
        error = {}
        
        Test = get_model('test')
#        objs = Tasks_Develop.filter(Tasks_Develop.c.task_sys == data['system'])
#        obj = None
        if Test.filter(and_(Test.c.system == int(data['system']),Test.c.function_code == data['function_code'])).count()>1:
            error['function_code'] = u'功能代码重复，请检查！'
#        for x in objs:
#            if x.version_date == data['version_date']:
#                obj = x
#                break
#        System = get_model('system')
#        sys = System.get(System.c.id==int(data['system']))
#        version = sys.abbr+'_'+str(data['version_date'])
#        sysname = sys.sys_id + '-' +sys.abbr+'('+sys.name+')'
#        if obj:
#            error={}
#        else:
#            error['version_date'] = '在系统中不存在测试版本为'+str(version)+'的可开发任务'
        return error

from uliweb.utils.generic import ReferenceSelectField
class SysFunctionImportForm(form.Form):
#    system = ReferenceSelectField('system', label='所属系统', required=True)
    func_file = form.FileField('导入文件', required=True)
    
    def form_validate(self, data):
        error = {}
        
        return error
